package org.dream.adam;

import java.util.ArrayList;
import java.util.List;

import org.dream.domain.Daydeal;
import org.dream.util.DoubleUtil;

/**
 * 双重映像
 * 
 * @author qiuriyuchen E-mail:panpan_001@126.com
 */
public class DoubleImage {
	/**
	 * 根据当前和以前的点，算出以后的第二映像点
	 * 
	 * @param old
	 * @param now
	 * @return
	 */
	public static double calculateAfter(double old, double now) {
		return now + (now - old);
	}

	/**
	 * 得到未来几天的镜像
	 * 
	 * @param list
	 * @param num
	 * @return
	 */
	public static List<Daydeal> getDaydealsImage(List<Daydeal> list, int num) {
		List<Daydeal> listR = new ArrayList<Daydeal>();
		Daydeal now = list.get(list.size() - 1);
		Daydeal pre = now;
		double nowCenter = (now.getOPEN() + now.getCLOSE()) / 2;
		for (int i = list.size() - 2; i >= list.size() - 1 - num && i >= 0; i--) {
			Daydeal old = list.get(i);
			Daydeal daydealImage = new Daydeal();
			daydealImage.setCode(now.getCode());
			daydealImage.setDAY(now.getDAY());
			daydealImage.setVOL(now.getVOL());

			daydealImage.setOPEN(DoubleImage.calculateAfter(old.getCLOSE(), nowCenter));
			daydealImage.setCLOSE(DoubleImage.calculateAfter(old.getOPEN(), nowCenter));
			daydealImage.setHIGH(DoubleImage.calculateAfter(old.getLOW(), nowCenter));
			daydealImage.setLOW(DoubleImage.calculateAfter(old.getHIGH(), nowCenter));
			double riseWidth = (daydealImage.getCLOSE() - pre.getCLOSE()) / pre.getCLOSE() * 100;
			riseWidth = DoubleUtil.changeDecimal(riseWidth, 6);
			daydealImage.setRiseWidth(riseWidth);
			pre = daydealImage;
			listR.add(daydealImage);
		}
		return listR;

	}
}
